package com.libre.view.setting;

import com.libre.constant.SysConstant;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import jdk.internal.util.xml.impl.Input;

import java.util.Locale;

/**
 * 设置
 */
public class SettingView extends Stage {

    public SettingView(BorderPane borderPane) {
        GridPane pane = new GridPane();
        pane.setPadding(new Insets(50));

        //语言
        Label language = new Label("语言：");
        pane.add(language, 0, 0);
        ChoiceBox choiceBox = new ChoiceBox(FXCollections.observableArrayList(SysConstant.I18N));
        choiceBox.setValue(SysConstant.I18N[0]);//默认值
        pane.add(choiceBox, 1, 0);

        //背景色
        Label background = new Label("背景色：");
        pane.add(background, 0, 1);
        ColorPicker colorPicker = new ColorPicker();
        colorPicker.setValue(Color.RED);
        pane.add(colorPicker, 1, 1);
        TextField textField = new TextField();
        colorPicker.setOnAction((ActionEvent t) -> {
            String colorHex = Integer.toHexString(colorPicker.getValue().hashCode()).substring(0, 6).toUpperCase();
            textField.setText(colorHex);
            textField.setStyle(String.format("-fx-background-color:#%s;-fx-border-color:#%s;", colorHex, colorHex));
            Color.valueOf(colorHex);
        });
        pane.add(textField, 2, 1);

        //保存
        Button save = new Button("保存");
        Image saveImage = new Image("./static/icon/edit.png");
        ImageView saveImageView = new ImageView(saveImage);
        saveImageView.setFitWidth(SysConstant.BUTTON_ICON_WIDTH);
        saveImageView.setFitHeight(SysConstant.BUTTON_ICON_HEIGHT);
        save.setGraphic(saveImageView);
        save.addEventHandler(MouseEvent.MOUSE_CLICKED, event->{
            Stage stage = new Stage();
            DialogPane dialogPane = new DialogPane();
            dialogPane.setContent(new Label("系统设置，需要重启才能生效"));
            Scene scene = new Scene(dialogPane);
            stage.setScene(scene);
            stage.show();
        });
        pane.add(save, 1, 2);
        //应用
        Button apply = new Button("应用");
        apply.addEventHandler(MouseEvent.MOUSE_CLICKED, event->{
//            Stage stage = new Stage();
//            DialogPane dialogPane = new DialogPane();
//            dialogPane.setContent(new Label("操作成功"));
//            Scene scene = new Scene(dialogPane);
//            stage.setScene(scene);
//            stage.show();

            Alert alert = new Alert(Alert.AlertType.INFORMATION);
            alert.titleProperty().set("信息");
            alert.headerTextProperty().set("操作成功");
            alert.showAndWait();
        });
        pane.add(apply, 2, 2);

        borderPane.setCenter(pane);
    }

}
